<template>
    <view class="content">
        <view class="box">
            <view class="notice" v-for="(item, index) in list" :key="index" @click="$gTo('../notice/details?id=' + item.id)">
                <view class="u-flex u-row-center">
                    <view class="time u-font-22">{{item.create_time}}</view>
                </view>
                <view class="notice-item">
                    <image :src="item.image" v-if="item.image"></image>
                    <view class="notice-text">
                        <view class="u-font-30 text-bold">{{item.title}}</view>
                        <view class="text u-padding-top-8 u-font-24 u-line-1">{{item.notice}}</view>
                    </view>
                    <view class="see">
                        <image src="../../static/icons/see.png" class="see-icon"></image>
                        <view>{{item.num}}浏览</view>
                    </view>
                </view>
            </view>
            
            <view style="height: 94rpx;padding-top: 30rpx;">
                <u-loadmore :status="status" v-if="status != 'loadmore'" />
            </view>
        </view>
        
        <view class="btn" @click="$gTo('../notice/create-notice')">添加公告</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [], 
            }
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            // 获取列表
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('notice', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail.data.length > 0) {
            				this.list = this.list.concat(ret.detail.data);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        },
    }
</script>

<style lang="scss">
    .see{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        font-size: 22rpx;
        color: #808080;
        padding: 10rpx 35rpx 40rpx;
    }
    .see-icon{
        width: 31rpx;
        height: 21rpx;
        margin-right: 10rpx;
    }
    
    
    
    .btn{
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 9;
        width: 100vw;
        font-size: 34rpx;
        color: #fff;
        text-align: center;
        padding: 25rpx;
        background-color: #00a1e9;
    }
    page {
        background: #f5f5f5;
    }
    .content{
        padding-bottom: 150rpx;
    }
    .box{
        padding: 0 20rpx 50rpx;
        margin-top: 30rpx;
    }
    
    //通用
    .time{
        color: #FFFFFF;
        background-color: #dfdfdf;
        padding: 10rpx 20rpx;
        border-radius: 50rpx;
        line-height: 1;
    }
    .text{
        color: #666666;
    }
    
    //平台公告
    .notice-item >image{
        width: 710rpx;
        height: 279rpx;
    }
    .notice-item{
       background-color: #FFFFFF;
       margin: 20rpx 0 30rpx;
       border-radius: 20rpx; 
       overflow: hidden;
    }
    .notice-text{
        padding: 30rpx 35rpx 10rpx;
    }
</style>

